/**
 * 更新角色
 * @url admin/system/role/sys/update
 * @description 更新角色信息
 */
module.exports = {
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '更新成功' };
		
		// 业务逻辑开始-----------------------------------------------------------
		let {
			_id,
			role_name,
			permission,
			comment
		} = data;
		
		if (!_id) {
			return { code: -1, msg: '角色ID不能为空' };
		}
		
		// 构建更新数据
		let updateData = {};
		if (role_name !== undefined) updateData.role_name = role_name;
		if (permission !== undefined) updateData.permission = permission;
		if (comment !== undefined) updateData.comment = comment;
		
		// 更新角色信息
		await db.collection('uni-id-roles').doc(_id).update(updateData);
		
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}

